package com.he.hsdyc.controller;

import com.he.hsdyc.model.User;
import com.he.hsdyc.model.User2;
import com.he.hsdyc.model.msg.ErrorCode;
import com.he.hsdyc.model.msg.Message;
import com.he.hsdyc.model.vo.AccountVO;
import com.he.hsdyc.model.vo.UserRegisterRequest;
import com.he.hsdyc.model.vo.UserVo;
import com.he.hsdyc.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Map;

@RestController
@Slf4j
@Api(value="LoginController",description="用户登录",tags={"用户登录"})
@RequestMapping("login")
public class LoginController {

    @Autowired
    private UserService userService;


    @ApiOperation("用户登录")
    @RequestMapping(value = "/login",method = RequestMethod.POST)
    public Map<?,?> login(@RequestBody AccountVO accountVO) throws Exception{
        return userService.login(accountVO.getUsername(), accountVO.getPassword());
    }



    @ApiOperation("用户注册")
    @RequestMapping(value = "/register",method = RequestMethod.POST )
    public Message register(@Valid @RequestBody UserVo userVO) throws Exception {
        userService.insertUser(userVO);
        return new Message(ErrorCode.SUCCESS);
    }
}
